package worldinruin.file.imp;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Settings {
	
	private final static String filePath = "playernames.txt";
	
	/**
	 * Saves player names.
	 * @param playerNames Player names.
	 * @throws IOException
	 */
	public static void savePlayerNames(List<String> playerNames) throws IOException{
		
		BufferedWriter out = new BufferedWriter(new FileWriter(filePath));
		
		for (String name : playerNames){
			out.write(name);
		}
		
		out.close();
		
	}
	
	/**
	 * Loads the saved player names.
	 * @return List of player names.
	 */
	public static List<String> loadPlayerNames(){
		
		Scanner sc = new Scanner(filePath);
		List<String> names = new ArrayList<String>();
		
		while(sc.hasNextLine()){
			names.add(sc.nextLine());
		}
		
		sc.close();
		
		return names;
		
		
	}

}
